import React, {useState, useEffect } from "react";
import http from "../../utils/http";
// 引入 ECharts 主模块
import * as echarts from "echarts";
export default function LineEchart(props) {
  const [incomedata, setIncomedata] = useState({})
  console.log(props.data);
  useEffect(() => {
    //  let xData=Object.keys(props.data)
      console.log(incomedata);
    http({
      url: "api/index/selectIncome",
      method: "get",
    }).then((res) => {
      console.log(res);
      if(res.code=200){
        setIncomedata(res.data.incomedata)
      }
    });
   

    var chartDom = document.getElementById("main");
    var myChart = echarts.init(chartDom);
    var option;
    option = {
      title: {
        text: "数据概况",
      },
      tooltip: {
        trigger: "axis",
      },
      legend: {
        data: ["all", "new"],
      },
      grid: {
        left: "3%",
        right: "4%",
        bottom: "3%",
        containLabel: true,
      },
      toolbox: {
        feature: {
          saveAsImage: {},
        },
      },
      xAxis: {
        type: "category",
        boundaryGap: false,
        data: ["1日", "2日", "3日", "4日", "5日", "6日"],
      },
      yAxis: {
        type: "value",
      },
      series: [
        {
          name: "all",
          type: "line",
          stack: "Total",
          data: [120, 132, 101, 134, 90, 230, 210],
        },
      ],
    };
    option && myChart.setOption(option);
    setTimeout(function () {
      window.onresize = function () {
        myChart.resize();
      };
    }, 200);
  }, [incomedata]);
  return <div id="main" style={{ width: "100%", height: 400 }}></div>;
}
